import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/mine/game_record/game_record_controller.dart';
import 'package:flutter_changdian_football/routers/app_routes.dart';
import 'package:flutter_changdian_football/utils/pull/pull_smart_refresher.dart';
import 'package:flutter_changdian_football/utils/str_utils.dart';
import 'package:flutter_changdian_football/widget/extended_image_slide_widget.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:get/get.dart';

/// 比赛记录
class GameRecordPage extends StatelessWidget {
  const GameRecordPage({super.key, this.clubId, this.isMy = 'N'});

  final String? clubId;

  final String isMy;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xffF8FAF9),
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: const Color(0xffF8FAF9),
        elevation: 0,
        title: Text(
          '比赛记录',
          style: TextStyle(fontSize: 16.sp, color: const Color(0xff333333)),
        ),
        iconTheme: const IconThemeData(
          color: Color(0xff333333)
        ),
      ),
      body: GetBuilder<GameRecordController>(
        init: GameRecordController(clubId: clubId),
        builder: (gameRecordController) {
          return RefreshWidget<GameRecordController>(
            child: ListView.separated(
              itemCount: gameRecordController.gameRecordModelList.length,
              padding: EdgeInsets.symmetric(vertical: 10.w),
              physics: const BouncingScrollPhysics(),
              separatorBuilder: (context, index) {
                return Container(
                  width: double.infinity,
                  height: 1.w,
                  color: const Color(0xffF8FAF9),
                  margin: EdgeInsets.symmetric(horizontal: 17.w),
                );
              },
              itemBuilder: (BuildContext context, int index) {
                return GestureDetector(
                  behavior: HitTestBehavior.translucent,
                  onTap: () {
                    Get.toNamed(AppRoutes.gameRecordDesc, parameters: {
                      'clubId': '${gameRecordController.gameRecordModelList[index].clubId}',
                      'matchId': '${gameRecordController.gameRecordModelList[index].matchId}'
                    });
                  },
                  child: Container(
                    padding: EdgeInsets.symmetric(vertical: 17.w),
                    color: Colors.white,
                    child: Row(
                      children: [
                        SizedBox(width: 17.w,),

                        if (isMy == 'Y') ...[
                          GestureDetector(
                            behavior: HitTestBehavior.translucent,
                            onTap: () {
                              if (gameRecordController.gameRecordModelList[index].clubImage != null) {
                                Get.to(
                                  ExtendedImageSlideWidget(
                                    url: "${gameRecordController.gameRecordModelList[index].clubImage ?? ''}",
                                  ),
                                  opaque: false
                                );
                              }
                            },
                            child: Container(
                              width: 48.w,
                              height: 48.w,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(8.r),
                              ),
                              child: ClipRRect(
                                borderRadius: BorderRadius.circular(8.r),
                                child: Image.network(gameRecordController.gameRecordModelList[index].clubImage ?? '', fit: BoxFit.fill,),
                              )
                            ),
                          ),
                  
                          SizedBox(width: 6.w,),
                        ],
                
                        Expanded(
                          child: Column(
                            children: [
                              Row(
                                children: [
                                  Expanded(
                                    child: Row(
                                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                      children: [
                                        SizedBox(
                                          child: Text(gameRecordController.gameRecordModelList[index].clubName ?? '', style: TextStyle(fontSize: 15.sp, color: const Color(0xff333333), fontWeight: FontWeight.w500),),
                                        ),
                        
                                        Container(
                                          decoration: BoxDecoration(
                                            color: StrUtils.getBackgroundColor(gameRecordController.gameRecordModelList[index].matchRulesValue),
                                            borderRadius: BorderRadius.only(
                                              topLeft: Radius.circular(16.r),
                                              bottomLeft: Radius.circular(16.r)
                                            )
                                          ),
                                          padding: EdgeInsets.symmetric(vertical: 6.w, horizontal: 14.w),
                                          child: Text(gameRecordController.gameRecordModelList[index].matchRulesName ?? '', style: TextStyle(fontSize: 11.sp, color: StrUtils.getTextColor(gameRecordController.gameRecordModelList[index].matchRulesValue)),),
                                        )
                                      ],
                                    ),
                                  )
                                ],
                              ),
                
                              SizedBox(height: 4.w,),
                        
                        
                              Row(
                                children: [
                                  Expanded(
                                    child: Row(
                                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                      children: [
                                        SizedBox(
                                          child: Text(gameRecordController.gameRecordModelList[index].matchCourtName ?? '', style: TextStyle(fontSize: 14.sp, color: const Color(0xff999999)),),
                                        ),
                            
                                        Container(
                                          margin: EdgeInsets.only(right: 17.w),
                                          child: Text(gameRecordController.gameRecordModelList[index].matchTime ?? '', style: TextStyle(fontSize: 12.sp, color: const Color(0xffcccccc)),),
                                        ),
                                      ],
                                    ),
                                  )
                                ],
                              )
                            ],
                          ),
                        )
                
                      ],
                    ),
                  ),
                );
              },
            ),
          );
        }
      ),
    );
  }
}